<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="用户ID，外键，与用户表关联" prop="userId">
        <el-input
          v-model="queryParams.userId"
          placeholder="请输入用户ID，外键，与用户表关联"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="演出ID，外键，与演出详情表关联" prop="perfDetId">
        <el-input
          v-model="queryParams.perfDetId"
          placeholder="请输入演出ID，外键，与演出详情表关联"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="地址ID，外键，与地址详情表关联" prop="addrDetId">
        <el-input
          v-model="queryParams.addrDetId"
          placeholder="请输入地址ID，外键，与地址详情表关联"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="地址ID，外键，与物流信息表关联" prop="logisticsInfoId">
        <el-input
          v-model="queryParams.logisticsInfoId"
          placeholder="请输入地址ID，外键，与物流信息表关联"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="订单号" prop="orderNumber">
        <el-input
          v-model="queryParams.orderNumber"
          placeholder="请输入订单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="下单时间" prop="orderTime">
        <el-date-picker clearable
          v-model="queryParams.orderTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择下单时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="预计送达时间" prop="estimatedDelivery">
        <el-date-picker clearable
          v-model="queryParams.estimatedDelivery"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择预计送达时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="付款时间" prop="payTime">
        <el-date-picker clearable
          v-model="queryParams.payTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择付款时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="支付方式" prop="payMethod">
        <el-input
          v-model="queryParams.payMethod"
          placeholder="请输入支付方式"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="收获时间" prop="receiveTime">
        <el-date-picker clearable
          v-model="queryParams.receiveTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择收获时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="配送方式" prop="deliveryMethod">
        <el-input
          v-model="queryParams.deliveryMethod"
          placeholder="请输入配送方式"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="截止取票时间" prop="cutoffTime">
        <el-date-picker clearable
          v-model="queryParams.cutoffTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择截止取票时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="取票地点" prop="pickupLocation">
        <el-input
          v-model="queryParams.pickupLocation"
          placeholder="请输入取票地点"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="演出名称" prop="perfName">
        <el-input
          v-model="queryParams.perfName"
          placeholder="请输入演出名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="演出时间" prop="perfTime">
        <el-date-picker clearable
          v-model="queryParams.perfTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择演出时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="取票二维码图片URL" prop="ticketQrCode">
        <el-input
          v-model="queryParams.ticketQrCode"
          placeholder="请输入取票二维码图片URL"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="二维码编号" prop="ticketQrId">
        <el-input
          v-model="queryParams.ticketQrId"
          placeholder="请输入二维码编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['st:orderDetail:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['st:orderDetail:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['st:orderDetail:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['st:orderDetail:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="orderDetailList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键，唯一标识订单详情" align="center" prop="id" />
      <el-table-column label="用户ID，外键，与用户表关联" align="center" prop="userId" />
      <el-table-column label="演出ID，外键，与演出详情表关联" align="center" prop="perfDetId" />
      <el-table-column label="地址ID，外键，与地址详情表关联" align="center" prop="addrDetId" />
      <el-table-column label="地址ID，外键，与物流信息表关联" align="center" prop="logisticsInfoId" />
      <el-table-column label="订单状态" align="center" prop="orderStatus" />
      <el-table-column label="订单号" align="center" prop="orderNumber" />
      <el-table-column label="下单时间" align="center" prop="orderTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.orderTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="预计送达时间" align="center" prop="estimatedDelivery" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.estimatedDelivery, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="付款时间" align="center" prop="payTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.payTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="支付方式" align="center" prop="payMethod" />
      <el-table-column label="收获时间" align="center" prop="receiveTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.receiveTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="配送方式" align="center" prop="deliveryMethod" />
      <el-table-column label="截止取票时间" align="center" prop="cutoffTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.cutoffTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="取票地点" align="center" prop="pickupLocation" />
      <el-table-column label="演出名称" align="center" prop="perfName" />
      <el-table-column label="演出时间" align="center" prop="perfTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.perfTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="取票二维码图片URL" align="center" prop="ticketQrCode" />
      <el-table-column label="二维码编号" align="center" prop="ticketQrId" />
      <el-table-column label="观演人ID列表,存储观演人ID" align="center" prop="attendeeIds" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['st:orderDetail:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['st:orderDetail:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改订单详情 (st_order_detail)对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="用户ID，外键，与用户表关联" prop="userId">
          <el-input v-model="form.userId" placeholder="请输入用户ID，外键，与用户表关联" />
        </el-form-item>
        <el-form-item label="演出ID，外键，与演出详情表关联" prop="perfDetId">
          <el-input v-model="form.perfDetId" placeholder="请输入演出ID，外键，与演出详情表关联" />
        </el-form-item>
        <el-form-item label="地址ID，外键，与地址详情表关联" prop="addrDetId">
          <el-input v-model="form.addrDetId" placeholder="请输入地址ID，外键，与地址详情表关联" />
        </el-form-item>
        <el-form-item label="地址ID，外键，与物流信息表关联" prop="logisticsInfoId">
          <el-input v-model="form.logisticsInfoId" placeholder="请输入地址ID，外键，与物流信息表关联" />
        </el-form-item>
        <el-form-item label="订单号" prop="orderNumber">
          <el-input v-model="form.orderNumber" placeholder="请输入订单号" />
        </el-form-item>
        <el-form-item label="下单时间" prop="orderTime">
          <el-date-picker clearable
            v-model="form.orderTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择下单时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="预计送达时间" prop="estimatedDelivery">
          <el-date-picker clearable
            v-model="form.estimatedDelivery"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择预计送达时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="付款时间" prop="payTime">
          <el-date-picker clearable
            v-model="form.payTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择付款时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="支付方式" prop="payMethod">
          <el-input v-model="form.payMethod" placeholder="请输入支付方式" />
        </el-form-item>
        <el-form-item label="收获时间" prop="receiveTime">
          <el-date-picker clearable
            v-model="form.receiveTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择收获时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="配送方式" prop="deliveryMethod">
          <el-input v-model="form.deliveryMethod" placeholder="请输入配送方式" />
        </el-form-item>
        <el-form-item label="截止取票时间" prop="cutoffTime">
          <el-date-picker clearable
            v-model="form.cutoffTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择截止取票时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="取票地点" prop="pickupLocation">
          <el-input v-model="form.pickupLocation" placeholder="请输入取票地点" />
        </el-form-item>
        <el-form-item label="演出名称" prop="perfName">
          <el-input v-model="form.perfName" placeholder="请输入演出名称" />
        </el-form-item>
        <el-form-item label="演出时间" prop="perfTime">
          <el-date-picker clearable
            v-model="form.perfTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择演出时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="取票二维码图片URL" prop="ticketQrCode">
          <el-input v-model="form.ticketQrCode" placeholder="请输入取票二维码图片URL" />
        </el-form-item>
        <el-form-item label="二维码编号" prop="ticketQrId">
          <el-input v-model="form.ticketQrId" placeholder="请输入二维码编号" />
        </el-form-item>
        <el-form-item label="观演人ID列表,存储观演人ID" prop="attendeeIds">
          <el-input v-model="form.attendeeIds" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listOrderDetail, getOrderDetail, delOrderDetail, addOrderDetail, updateOrderDetail } from "@/api/st/orderDetail";

export default {
  name: "OrderDetail",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 订单详情 (st_order_detail)表格数据
      orderDetailList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userId: null,
        perfDetId: null,
        addrDetId: null,
        logisticsInfoId: null,
        orderStatus: null,
        orderNumber: null,
        orderTime: null,
        estimatedDelivery: null,
        payTime: null,
        payMethod: null,
        receiveTime: null,
        deliveryMethod: null,
        cutoffTime: null,
        pickupLocation: null,
        perfName: null,
        perfTime: null,
        ticketQrCode: null,
        ticketQrId: null,
        attendeeIds: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询订单详情 (st_order_detail)列表 */
    getList() {
      this.loading = true;
      listOrderDetail(this.queryParams).then(response => {
        this.orderDetailList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        userId: null,
        perfDetId: null,
        addrDetId: null,
        logisticsInfoId: null,
        orderStatus: null,
        orderNumber: null,
        orderTime: null,
        estimatedDelivery: null,
        createTime: null,
        payTime: null,
        payMethod: null,
        receiveTime: null,
        deliveryMethod: null,
        cutoffTime: null,
        pickupLocation: null,
        perfName: null,
        perfTime: null,
        ticketQrCode: null,
        ticketQrId: null,
        attendeeIds: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加订单详情 (st_order_detail)";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getOrderDetail(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改订单详情 (st_order_detail)";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateOrderDetail(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addOrderDetail(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除订单详情 (st_order_detail)编号为"' + ids + '"的数据项？').then(function() {
        return delOrderDetail(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('st/orderDetail/export', {
        ...this.queryParams
      }, `orderDetail_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
